<template>
  <div class="closing">
    <div>
      <el-button size="mini" @click="handleGetUntreated">{{ $t('btn.reload') }}</el-button>
      <el-button type="primary" size="mini" @click="isClosingDialog=true">{{ $t('market.filter') }}</el-button>
    </div>
    <div class="header">
      <div class="header-name">
        <span>{{ $t('market.period') }}</span>
        <el-input v-model="fperiod" size="mini" disabled />
      </div>
      <!--      当前关账期间-->
      <dataRow ref="mainData" />
    </div>
    <div class="table-content">
      <jc-table
        v-loading="loading"
        :table-data="tableData"
        :table-header="tableHeader"
        :table-height="tableHeight"
        table-selection
        sortable
        :get-summaries="getSummaries"
        show-summary
        @selectionChange="selectionDatas"
      >
        <!--    物料编码    -->
        <template v-slot:orderSlot="col">
          <el-link type="primary" @click="jumpMateriel(col.scope.row)">
            {{ col.scope.row.fnumber }}
          </el-link>
        </template>
        <!--    调整单    -->
        <template v-slot:billSlot="col">
          <el-link type="primary" @click="pushView(col.scope.row)">
            {{ col.scope.row.frombillNo }}
          </el-link>
        </template>
      </jc-table>
    </div>
    <!-- 异常余额汇总 -->
    <el-dialog
      v-dialogDrag
      :title="$t('menu.abnormalList')"
      model
      :visible.sync="isClosingDialog"
      :close-on-click-modal="false"
      width="600px"
      top="5vh"
      center
    >
      <div>
        <el-form :model="subDetails" size="mini" label-width="100px">
          <el-form-item :label="$t('market.checkDate')">
            <el-date-picker
              v-model="subDetails.fperiod"
              type="month"
              value-format="yyyy-MM"
              style="width: 152px"
              placeholder="选择月"
            />
          </el-form-item>
          <el-form-item :label="$t('market.frombillNunber')">
            <el-input v-model.trim="subDetails.frombillNo" />
          </el-form-item>
          <el-form-item :label="$t('market.fmaterial')">
            <el-input v-model.trim="subDetails.materialNumber" />
          </el-form-item>
          <el-form-item :label="$t('market.stockname')">
            <el-input v-model.trim="subDetails.stockName" />
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="isClosingDialog = false">{{ $t('btn.cancel') }}</el-button>
        <el-button type="primary" @click="initialCon">{{ $t('btn.confirm') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  queryExceptionGatherList
} from '@/api/financial/warehousing'
import dataRow from '@/views/financial/company/components/dataRow'
import searData from '@/components/Search/mixin'

export default {
  name: 'AbnormalList',
  components: {
    dataRow
  },
  mixins: [searData],
  data() {
    return {
      subDetails: {
        fperiod: '',
        stockName: '',
        materialNumber: '',
        frombillNo: '',
        pageSize: 10,
        pageNum: 1
      },
      fperiod: '',
      loading: false,
      isClosingDialog: false,
      // 表头
      selectData: [],
      tableData: [],
      tableHeight: '70vh',
      tableHeader: [
        { label: this.$t('market.period'), prop: 'fperiod' },
        { label: this.$t('market.fmaterial'), type: 'order', prop: 'fnumber' },
        { label: this.$t('shop.fname2'), prop: 'fname' },
        { label: this.$t('market.fmodel'), prop: 'fmodel' },
        { label: this.$t('market.fdescripTion'), prop: 'fdescription' },
        { label: this.$t('market.stockNumber'), prop: 'stockNumber' },
        { label: this.$t('market.stock2'), prop: 'stockName' },
        { label: this.$t('market.fqty'), prop: 'fqty', align: 'right', width: '100' },
        { label: this.$t('market.singleprice'), prop: 'fsingleprice', align: 'right', width: '100' },
        { label: this.$t('market.singleAmount'), prop: 'famount', align: 'right', width: '100' },
        { label: this.$t('market.adjustCorr'), type: 'bill', prop: 'frombillNo' }
      ]
    }
  },
  created() {
    this.tableHeight = window.innerWidth > 1440 ? 'calc(100vh - 200px)' : '73vh'
  },
  methods: {
    // 过滤确认
    initialCon() {
      this.isClosingDialog = false
      const { fperiod } = this.subDetails
      this.fperiod = fperiod
      this.handleGetUntreated()
    },
    // 获取入库成本维护列表数据
    async handleGetUntreated() {
      this.loading = true
      if (!this.fperiod) {
        this.isClosingDialog = true
        this.loading = false
        return
      }
      const DATA = { ...this.subDetails }
      const RES = await queryExceptionGatherList(DATA)
      if (RES.code === 0) {
        this.loading = false
        this.tableData = RES.data.list
      } else {
        this.loading = false
        this.$confirm(RES.message, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'error'
        })
      }
    },
    // 全选
    selectionDatas(val) {
      this.selectData = val
    },
    pushView(ev) {
      this.$router.push({ path: `/adjustmentDetails/${ev.frombillId}` })
    }
  }
}
</script>
<style lang="scss" scoped>
.closing {
  @include listBom;
  .el-input::v-deep .el-input__inner {
    height: 30px;
    line-height: 30px;
  }
  .header{
    margin-top: 10px;
    .header-name{
      span {
        width: 100px;
        margin-right: 10px;
        text-align: right;
      }
    }
  }
}
</style>
